/**
 * @version Create on 2012-11-1
 * @author Yinzi Chen
 */

public class BestTimeToStockII {

	public int maxProfit(int[] prices) {
		int r = 0;
		for (int m = 1 << 31, i = 0; i < prices.length; ++i) {
			r = Math.max(r, m + prices[i]);
			m = Math.max(m, r - prices[i]);
		}
		return r;
	}

	public static void main(String[] args) {

	}
}
